﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Reconciliation.Data
{
    public partial class CaseClientComment
    {
        public static Domain.CaseClientComment MapDataToDomain(Data.CaseClientComment dataCaseClientComment)
        {
            Domain.CaseClientComment domainCaseClientComment = new Reconciliation.Domain.CaseClientComment();
            domainCaseClientComment.CaseClientCommentID = dataCaseClientComment.CaseClientCommentID ;
            domainCaseClientComment.ClientName = dataCaseClientComment.ClientName;
            domainCaseClientComment.Comment = dataCaseClientComment.Comment;
            domainCaseClientComment.DateTime = dataCaseClientComment.DateTime;            
            return domainCaseClientComment;
        }

        public static Data.CaseClientComment MapDomainToData(Domain.CaseClientComment domainCaseClientComment)
        {
            Data.CaseClientComment dataCaseClientComment = new Reconciliation.Data.CaseClientComment();
            dataCaseClientComment.ClientName = domainCaseClientComment.ClientName;
            dataCaseClientComment.Comment = domainCaseClientComment.Comment;
            dataCaseClientComment.DateTime = DateTime.Now;
            dataCaseClientComment.CaseReference.EntityKey = new System.Data.EntityKey("ReconciliationEntities.Case", "CaseID", domainCaseClientComment.Case.CaseID);
            return dataCaseClientComment;
        }

        public static List<Domain.CaseClientComment> GetCaseClientComment(int caseID)
        {
            List<Domain.CaseClientComment> domainCaseClientCommentList = new List<Reconciliation.Domain.CaseClientComment>();
            Domain.CaseClientComment domainCaseClientComment = new Reconciliation.Domain.CaseClientComment();
            ReconciliationEntities recEnt = new ReconciliationEntities();
            List<Data.CaseClientComment> dataCaseAuditorComment = recEnt.CaseClientComment.Where(c => c.Case.CaseID.Equals(caseID)).ToList();
            foreach (Data.CaseClientComment cac in dataCaseAuditorComment)
            {
                domainCaseClientComment = CaseClientComment.MapDataToDomain(cac);
                domainCaseClientCommentList.Add(domainCaseClientComment);
            }
            return domainCaseClientCommentList;
        }

        public static void SetCaseClientComment(Domain.CaseClientComment domainCaseClientComment)
        {
                using(ReconciliationEntities recEnt = new ReconciliationEntities())
            {
                Data.CaseClientComment dataClientComment = Data.CaseClientComment.MapDomainToData(domainCaseClientComment);
                recEnt.AddToCaseClientComment(dataClientComment);
                recEnt.SaveChanges();
            }
        }

    }
}
